package com.jinyi.wwdeng.ui.launch

import android.os.Bundle
import android.view.View
import com.jinyi.base.utils.BarUtils
import com.jinyi.wwdeng.AppConfigs
import com.jinyi.wwdeng.databinding.ActLaunchBinding
import com.jinyi.wwdeng.network.ApiService
import com.jinyi.wwdeng.pro.ProMvpAct
import com.jinyi.wwdeng.ui.launch.contract.LaunchContract
import com.jinyi.wwdeng.ui.launch.impl.LaunchPresenterImpl
import com.jinyi.wwdeng.ui.login.LoginAct
import com.jinyi.wwdeng.ui.main.act.MainAct
import com.jinyi.wwdeng.ui.permission.PermissionAct
import com.jinyi.wwdeng.utils.event.TrackEventType
import com.jinyi.wwdeng.utils.event.TrackEventUtils
import org.json.JSONObject
import java.util.TimeZone

/**
 * JinYiTest
 * @Author wwdeng
 * @CreateTime: 2024/4/15 14:34
 * @Annotation：启动页
 */
class LaunchAct: ProMvpAct<LaunchContract.View, LaunchPresenterImpl>(), LaunchContract.View {

    lateinit var binding: ActLaunchBinding

    override fun getRootView(): View {
        binding = ActLaunchBinding.inflate(layoutInflater)
        return binding.root
    }

    override fun createPresenter(): LaunchPresenterImpl {
        return LaunchPresenterImpl()
    }

    override fun initView() {
        BarUtils.setStatusBarLightMode(this, false)
        initPresenter()
    }

    override fun initListener() {
    }

    override fun initData() {
        //获取地区转发 Timezone
        val params = JSONObject().apply {
            put("p",AppConfigs.AppName)
            put("tz", TimeZone.getDefault().id)
        }
        presenter.loadTimezoneRequest(params)
    }

    /**
     * 获取地区转发成功
     */
    override fun showTimeZoneSuccess(timeZone: String) {
        TrackEventUtils.logEvent(TrackEventType.PAGE.PAGE_LAUNCH_START,"")
        val params = JSONObject().apply {
            put("product",AppConfigs.AppName)
            put("path",ApiService.API_PATH.API_PATH_APP_INFO)
        }
        presenter.loadAppInfoRequest(params)
    }

    /**
     * 进入权限申请
     */
    override fun showPermissionAction(permissings: String) {
        val bundle = Bundle()
        bundle.putString("Permissings",permissings)
        onIntent(PermissionAct::class.java,bundle)
        finish()
    }

    /**
     * 进入登录
     */
    override fun showLoginAction() {
        onIntent(LoginAct::class.java)
        finish()
    }

    /**
     * 进入主页
     */
    override fun showMainAction() {
        onIntent(MainAct::class.java)
        finish()
    }

    override fun showFailure(errorMsg: String?) {
        showToast(errorMsg)
    }

    override fun onDestroy() {
        super.onDestroy()
        TrackEventUtils.logEvent(TrackEventType.PAGE.PAGE_LAUNCH_END,"")
    }
}